﻿using System.Linq;
using Abp.Authorization;
using Abp.Localization;
using LeadThing.AbpZeroTemplate.Authorization;



namespace LeadThing.AbpZeroTemplate.CallPolices.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="CallPoliceAppPermissions"/> for all permission names.
    /// </summary>
    public class CallPoliceAppAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            //在这里配置了CallPolice 的权限。

            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

            var entityNameModel = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_XueLiangGongCheng)
              ?? pages.CreateChildPermission(AppPermissions.Pages_XueLiangGongCheng, L("Pages_XueLiangGongCheng"));

            //视频监控
            var shiPinJianKong= entityNameModel.CreateChildPermission(CallPoliceAppPermissions.ShiPinJianKong, L("Pages_ShiPinJianKong"));

            //一键报警菜单
            var callPoliceManage = entityNameModel.CreateChildPermission(CallPoliceAppPermissions.CallPoliceManage, L("CallPoliceManage"));

            //一键报警发起
            var callPolice = callPoliceManage.CreateChildPermission(CallPoliceAppPermissions.CallPolice, L("CallPolice"));
            callPolice.CreateChildPermission(CallPoliceAppPermissions.CallPolice_CreateCallPolice, L("CreateCallPolice"));
            callPolice.CreateChildPermission(CallPoliceAppPermissions.CallPolice_EditCallPolice, L("EditCallPolice"));
            callPolice.CreateChildPermission(CallPoliceAppPermissions.CallPolice_DeleteCallPolice, L("DeleteCallPolice"));

            //报警受理
            var callPoliceAcceptance = callPoliceManage.CreateChildPermission(CallPoliceAppPermissions.CallPoliceAcceptance, L("CallPoliceAcceptance"));
            callPoliceAcceptance.CreateChildPermission(CallPoliceAppPermissions.CallPoliceAcceptance_HandleSuggestion, L("HandleSuggestion"));
            callPoliceAcceptance.CreateChildPermission(CallPoliceAppPermissions.CallPoliceAcceptance_Detail, L("Detail"));
            callPoliceAcceptance.CreateChildPermission(CallPoliceAppPermissions.CallPoliceAcceptance_ViewWorkFlowProcess, L("ViewWorkFlowProcess"));

            //结案归档
            var jieAnGuiDang = callPoliceManage.CreateChildPermission(CallPoliceAppPermissions.JieAnGuiDang, L("JieAnGuiDang"));
            jieAnGuiDang.CreateChildPermission(CallPoliceAppPermissions.JieAnGuiDang_ClosedSuggestion, L("ClosedSuggestion"));
            jieAnGuiDang.CreateChildPermission(CallPoliceAppPermissions.JieAnGuiDang_Detail, L("Detail"));
            jieAnGuiDang.CreateChildPermission(CallPoliceAppPermissions.JieAnGuiDang_ViewWorkFlowProcess, L("ViewWorkFlowProcess"));

        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AbpZeroTemplateConsts.LocalizationSourceName);
        }
    }
}